// https://blog.csdn.net/Andius/article/details/140065488

#include <alsa/asoundlib.h>
#include <iostream>

// 将当前所有的音频设备全部列举
int main() 
{
    snd_ctl_t *handle;
    snd_ctl_card_info_t *info;
    int card = -1;

    snd_ctl_card_info_alloca(&info);

    // Iterate over sound cards
    while (snd_card_next(&card) >= 0 && card >= 0) 
    {
        char name[32];
        sprintf(name, "hw:%d", card);

        if (snd_ctl_open(&handle, name, 0) < 0) 
        {
            std::cerr << "Cannot open control for card " << card << std::endl;
            continue;
        }

        if (snd_ctl_card_info(handle, info) < 0) 
        {
            std::cerr << "Cannot get card info for card " << card << std::endl;
            snd_ctl_close(handle);
            continue;
        }

        std::cout << "Card " << card << ": " << snd_ctl_card_info_get_name(info) << std::endl;

        snd_ctl_close(handle);
    }

    return 0;
}


